/**   
 * @Title: HyVerifyPriceController.java 
 * @Package com.hanyong.admin.controller.hyInformationVerify
 * @Description: TODO(用一句话描述该文件做什么) 
 * @author Li  
 * @date 2018年10月9日11:39:30
 * @version V1.0   
 */
package com.hyfrogx.modules.information.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hyfrogx.common.utils.R;
import com.hyfrogx.modules.information.entity.HyVerifyPriceEntity;
import com.hyfrogx.modules.information.service.HyVerifyPriceService;
import com.hyfrogx.modules.sys.controller.AbstractController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName: HyVerifyPriceController
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author Li
 * @date 2018年3月12日10:43:01
 * 
 */

@RestController
@RequestMapping(value = "verifyPrice")
@Api(value = "HyVerifyPriceController", tags = {"后台--资讯号定价管理"})
/*@Api(value = "HyVerifyPriceController", tags = {"后台--资讯定价管理"})*/
public class HyVerifyPriceController extends AbstractController {
	
	@Autowired
	private HyVerifyPriceService verifyPriceService;
	
	/**
	 * 获取所有资讯号认证定价
	 * @return int
	 * @throws Exception
	 */
	@RequestMapping(value = "getList", method = RequestMethod.POST)
  @ApiOperation("获取所有资讯号认证定价")
	public R getList() {
			List<HyVerifyPriceEntity> list = verifyPriceService.getBaseMapper().selectList(new QueryWrapper<>());
			if(list.size()>0){
			  return R.ok().put("result",list);
      }
			return R.error("查询失败");
	}

	/**
   *
   * 收费配置
	 * 获取当前资讯号认证定价
	 * @return int
	 * @throws Exception
	 */
	@RequestMapping(value = "/getPrice", method = RequestMethod.GET)
  @ApiOperation("获取当前资讯号认证定价")
	public R getPrice() {
			HyVerifyPriceEntity hyVerifyPrice = verifyPriceService.getBaseMapper().selectOne(new QueryWrapper<>());
			if (hyVerifyPrice != null) {
				return R.ok().put("result",hyVerifyPrice);
			}
				return R.error("查询失败");
	}

	/**
	 * 修改价格
	 * @return int
	 * @throws Exception
	 */
	@RequestMapping(value = "updatePrice", method = RequestMethod.POST)
  @ApiOperation("修改当前资讯号认证定价")
	public R update(@RequestBody HyVerifyPriceEntity hyVerifyPrice) {
			if(hyVerifyPrice.getId() == null){
				return R.error("id必传");
			}
			if(verifyPriceService.updateById(hyVerifyPrice)){
        return R.ok("修改成功");
      }
      return R.error("修改失败");
	}

	/**
	 * 增加记录
	 * @return int
	 * @throws Exception
	 */
	@RequestMapping(value = "add", method = RequestMethod.POST)
  @ApiOperation("创建资讯号认证定价")
	public R add(@RequestBody HyVerifyPriceEntity hyVerifyPrice) {
	  if(verifyPriceService.getBaseMapper().selectCount(new QueryWrapper<HyVerifyPriceEntity>())>0){
	    return R.error("资讯号收费配置已存在");
    }
	    if(hyVerifyPrice.getPrice()==null){
        return R.error("请输入价格");
      }
    if(hyVerifyPrice.getTrueprice()==null){
      return R.error("请输入优惠价格");
    }
			if (verifyPriceService.getBaseMapper().insert(hyVerifyPrice) > 0) {
				return R.ok("创建成功");
			}
			return R.error("创建失败");
	}
}
